//
// Created by Semir on 2020/5/7.
//

#include <iostream>

using namespace std;

void Swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

bool duplicate(int numbers[], int length, int* duplication) {
    if (numbers == nullptr || length <= 0) {
        return false;
    }
    int index = 0;
    while (index < length) {
        while (numbers[index] != index) {
            if (numbers[index] == numbers[numbers[index]]) {
                *duplication = numbers[index];
                return true;
            } else {
                Swap(&numbers[numbers[index]], &numbers[index]);
            }
        }
        index++;
    }
    return false;
}

void Test() {
    int numbers[7] = {2,3,1,0,2,5,3};
    int length = 7;
    int a = 0;
    bool res = duplicate(numbers, length, &a);
    cout << res << endl;
    cout << a << endl;

}

int main() {
    Test();
    return 0;
}